'''
Created on May 8, 2012
TC ID: Ecom_5048
Desc: Kiem thu chuc nang sua thong tin bai kiem tra
@author: lavang
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.lessonInformationFunc import clickOnLesson
from Functions.testsFunc import clickOnTests, addTest,\
    isTestAddedSuccessfully, clickOnATest

username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson=readData("lessonName",index=2)
tm_test=readData("testName",index=2)
tm_testChanged=readData("testName",index=3)
tm_description="This is final Test"
tm_parentUnit=readData("subUnitName",index=2)
class Ecom_5048(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5048(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao mot bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao 'Tests'"
        clickOnTests(self)
        
        print "Buoc 4: Click vao bai kiem tra muon sua thong tin "
        clickOnATest(self,tm_test)
        
        print "Buoc 5: Sua thong tin bai kiem tra"
        addTest(self,tm_testChanged,tm_description,tm_parentUnit,edit='on')
        
        print "Buoc 7: Xac nhan sua thong tin bai kiem tra thanh cong"
        self.assertTrue(isTestAddedSuccessfully(self,tm_testChanged,tm_parentUnit), "Failed!")
        print "Passed! Bai kiem tra duoc sua thong tin thanh cong"
        
    def tearDown(self):
        endCondition(self)



if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5048)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin bai kiem tra'
                    )
    runner.run(suite)